package com.vae.learn.api;

import com.vae.base.exception.SystemException;
import com.vae.base.model.page.PageResult;
import com.vae.base.utils.SecurityUtil;
import com.vae.dto.MyCourseTableParams;
import com.vae.dto.XcChooseCourseDto;
import com.vae.dto.XcCourseTablesDto;
import com.vae.entity.XcCourseTables;
import com.vae.learn.service.MyCourseTablesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 我的课程表接口
 */
@RestController
public class MyCourseTablesController {

    @Autowired
    MyCourseTablesService myCourseTablesService;

    @ApiOperation("添加选课")
    @PostMapping("/choosecourse/{courseId}")
    public XcChooseCourseDto addChooseCourse(@PathVariable("courseId") Long courseId) {

        //当前登录的用户
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        if(user == null){
            SystemException.cast("请登录");
        }
        //用户id
        String userId = user.getId();
        //添加选课
        XcChooseCourseDto xcChooseCourseDto = myCourseTablesService.addChooseCourse(userId, courseId);
        return xcChooseCourseDto;
    }

    @ApiOperation("查询学习资格")
    @PostMapping("/choosecourse/learnstatus/{courseId}")
    public XcCourseTablesDto getLearnstatus(@PathVariable("courseId") Long courseId) {
        //当前登录的用户
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        if(user == null){
            SystemException.cast("请登录");
        }
        //用户id
        String userId = user.getId();
        XcCourseTablesDto learningStatus = myCourseTablesService.getLearningStatus(userId, courseId);
        learningStatus.setCharge("201000");
        return learningStatus;
    }

    @ApiOperation("我的课程表")
    @GetMapping("/mycoursetable")
    public PageResult<XcCourseTables> mycoursetable(MyCourseTableParams params) {

        //当前登录的用户
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        if(user == null){
            SystemException.cast("请登录");
        }
        //用户id
        String userId = user.getId();
        params.setUserId(userId);

        PageResult<XcCourseTables> mycoursetables = myCourseTablesService.mycoursetables(params);
        return mycoursetables;
    }

}
